package tool

import (
	"net/http"
	response_enum "oc_saas/enum/response"

	"github.com/gin-gonic/gin"
)

// 返回的请求体
type Enum struct {
	Class []string `json:"class"`
	Error string   `json:"error"`
}

type Res struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Enum Enum        `json:"enum"` //特别标识码 用于前端判断返回的错误到底是什么
	Data interface{} `json:"data"`
}

func Result(code int, data interface{}, msg string, Enum Enum, c *gin.Context) {
	c.JSON(http.StatusOK, Res{
		Code: code,
		Data: data,
		Msg:  msg,
		Enum: Enum,
	})
}

func Ok(c *gin.Context) {
	Result(response_enum.SUCCESS, map[string]interface{}{}, response_enum.HttpBaseTag[response_enum.OPERA_SUCCESS], Enum{
		Class: []string{},
		Error: "",
	}, c)
}
func OkWithMessage(msg string, c *gin.Context) {
	Result(response_enum.SUCCESS, map[string]interface{}{}, msg, Enum{
		Class: []string{},
		Error: "",
	}, c)
}
func OkWithData(data interface{}, c *gin.Context) {
	Result(response_enum.SUCCESS, data, response_enum.HttpBaseTag[response_enum.OPERA_SUCCESS], Enum{
		Class: []string{},
		Error: "",
	}, c)
}

func Fail(c *gin.Context) {
	Result(response_enum.ERROR, map[string]interface{}{}, response_enum.HttpBaseTag[response_enum.OPERA_FAIL], Enum{
		Class: []string{},
		Error: "",
	}, c)
}
func FailWithMessage(msg string, Enum Enum, c *gin.Context) {
	Result(response_enum.ERROR, map[string]interface{}{}, msg, Enum, c)
}
func FailWithData(data interface{}, c *gin.Context) {
	Result(response_enum.ERROR, data, response_enum.HttpBaseTag[response_enum.OPERA_FAIL], Enum{
		Class: []string{},
		Error: "",
	}, c)
}
